<template>
  <div class="app-container">
    <el-row>
      <el-col :span="20">
        <el-button @click="dialogAddModuleVisible = true" type="primary">添加业务板块</el-button>
      </el-col>
      <!-- 模态框 -->
      <el-dialog title="业务板块" :visible.sync="dialogAddModuleVisible">
        <el-form :model="form">
          <el-form-item label="业务板块" :label-width="formLabelWidth">
            <el-input v-model="form.name" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="业务场景" :label-width="formLabelWidth">
            <el-select v-model="form.sence" placeholder="请选择业务场景">
              <el-option label="稻壳业务" value="docer"></el-option>
              <el-option label="会员业务" value="member"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogAddModuleVisible = false">取 消</el-button>
          <el-button type="primary" @click="dialogAddModuleVisible = false">确 定</el-button>
        </div>
      </el-dialog>

      <!-- 搜索框 -->
      <el-col :span="4">
        <el-form ref="form" :model="form" label-width="120px" align="right">
          <el-input v-model="input" width="50px" placeholder="请输入内容"></el-input>
        </el-form>
      </el-col>
    </el-row>
    <el-table :data="list" style="margin-top:10px">
      <el-table-column align="center" label="ID" width="95">
        <template v-slot="scope">{{ scope.$index+1 }}</template>
      </el-table-column>
      <el-table-column label="业务域" width="110" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.dataName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建者" width="110" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.createBy }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" width="110" align="center">
        <template slot-scope="scope">
          <el-tag :type="scope.row.status | statusFilter">
            {{ scope.row.status }}
          </el-tag>
          <!-- <span>{{ scope.row.status }}</span> -->
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.createTime }}</span>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getIndexList } from "@/api/table";

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'info',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      input: "",
      list: [
        {
          dataId: 4,
          dataName: "交易员"
        }
      ],
      listLoading: true,
      dialogAddModuleVisible: false,
      form: {
          name: '',
          sence: ''
      },
      formLabelWidth: '80px'
      // dataId: null
    };
  },
  created() {
    this.fetchData();
  },
  methods: {
    async fetchData() {
      this.listLoading = true;
      const { data } = await getIndexList();
      console.log(data.msg);
      this.list = data;
      this.listLoading = false;

      // getIndexList().then(response => {
      //   this.list = response.data;
      //   console.log(response.msg);
      // });
    }
  }
};
// export default {
//   filters: {
//     statusFilter(status) {
//       const statusMap = {
//         published: "success",
//         draft: "gray",
//         deleted: "danger"
//       };
//       return statusMap[status];
//     }
//   },
//   data() {
//     return {
//       input: "",
//       list: null,
//       listLoading: true
//     };
//   },
//   created() {
//     this.fetchData();
//   },
//   methods: {
//     fetchData() {
//       this.listLoading = true;
//       getList().then(response => {
//         this.list = response.data.items;
//         this.listLoading = false;
//       });
//       getIndexList().then(response => {
//         this.list = response.data.items;
//         this.listLoading = false;
//       });
//     }
//   }
// };
</script>
